/*
 *	@author	GeneZhao
 *	@date	2015-04-09 11:54:29
 *	@desc	
 */
Ext.define('kmsApp.view.oeminfo.OemInfoController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.oeminfo',
    saveOemInfo: function() {
        var me = this;
        var form = me.getOemInfoForm();

    },
    addHandle: function() {
        var me = this,
            win, grid;
        var form = me.getOemInfoForm(),
            win = me.getOemInfoWin(),
            grid = me.getView();
        win.add(form);
        win.addDocked({
            dock: 'bottom',
            ui: 'footer',
            xtype: 'toolbar',
            items: ['->', {
                text: '保存',
                glyph: 0xf0c7,
                handler: function() {
                    if (form.getForm().isValid()) {
                        form.getForm().submit({
                            waitMsg: '数据处理中...',
                            url: 'http://localhost:8080/KMS/oeminfo/saveOEMInfo',
                            success: function(form, action) {
                                var result = Ext.util.JSON.decode(action.response.responseText);
                                win.close();
                                grid.getStore().reload();

                                Ext.toast({
                                    html: result.msg,
                                    title: '提示',
                                    saveDelay: 10,
                                    align: 'br',
                                    closable: true,
                                    width: 200,
                                    useXAxis: true,
                                    slideInDuration: 500
                                });
                            },
                            failure: function(form, action) {
                                var result = Ext.util.JSON.decode(action.response.responseText);
                                win.close();
                                Ext.toast({
                                    html: result.msg,
                                    title: '提示',
                                    saveDelay: 10,
                                    align: 'br',
                                    closable: true,
                                    width: 200,
                                    useXAxis: true,
                                    slideInDuration: 500
                                });
                            }
                        });
                    }
                }
            }]
        });
        win.setTitle('新增OEM');
        win.show();
    },
    editHandle: function() {
        Ext.toast({
            html: '开发中...',
            title: '提示',
            saveDelay: 10,
            align: 'br',
            closable: true,
            width: 200,
            useXAxis: true,
            slideInDuration: 500
        });
    },
    getOemInfoForm: function() {
        var form;
        if (!form) {
            form = Ext.create('kmsApp.view.oeminfo.OemInfoForm');
        }
        return form;
    },
    getOemInfoWin: function() {
        var win;
        if (!win) {
            win = Ext.create('Ext.window.Window', {
                glyph: 0xf016,
                padding: '5 0 0 0',
                width: 400,
                height: 210,
                resizable: false
            });
        }
        return win;
    }
})
